package com.fancon.android.gardenjokesx.activity;

import java.net.URLDecoder;
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.androidquery.AQuery;
import com.fancon.android.gardenjokesx.R;
import com.fancon.android.gardenjokesx.entity.FacebookUser;
import com.fancon.android.gardenjokesx.utils.StringUtil;

public class P063Adapter extends BaseAdapter {

	private ArrayList<FacebookUser> listFacebookUsers;
	private LayoutInflater inflater;
	private AQuery aq;

	public P063Adapter(ArrayList<FacebookUser> listFacebookUsers,
			Context context) {
		super();
		this.listFacebookUsers = listFacebookUsers;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return listFacebookUsers.size();
	}

	@Override
	public Object getItem(int position) {
		return listFacebookUsers.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.p063_listitems, null);
		}
		
		if(listFacebookUsers.get(position).isChecked()){
			convertView.findViewById(R.id.p063_checkbox).setVisibility(View.VISIBLE);
			//Log.d("Pos_","Pos :" + position);
		}else{
			convertView.findViewById(R.id.p063_checkbox).setVisibility(View.INVISIBLE);
		}
		
		
		aq = new AQuery(convertView);
		aq.id(R.id.p063_username).text(StringUtil.validString(listFacebookUsers.get(position)
						.getUsername(), 20));
		aq.id(R.id.p063_avatar).visible().image(URLDecoder.decode(listFacebookUsers.get(position).getImageprofile()));
		return convertView;
	}
}
